using System;
using System.Collections;
using System.Reflection;
using DataBroker.Dao;

namespace FirebirdDAO
{
    ///<summary>
    /// DAO Class for the Proj_dept_budget table.
    ///</summary>
    public class Proj_dept_budget : Entity
    {
        private Int32 _FISCAL_YEAR;
        private String _PROJ_ID;
        private String _DEPT_NO;
        private Int32 _QUART_HEAD_CNT;
        private Decimal _PROJECTED_BUDGET;

        ///Default constructor
        public Proj_dept_budget()
        {

        }

        /// <summary>
        /// Constructor for joins. 
        /// Available PARENT tables to join with:
        ///    - DepartmentTable
        ///    - Project
        /// </summary>
        public Proj_dept_budget(bool Flat, params Entity[] entities)
            : this()
        {
            foreach (Entity entity in entities)
            {
                string[] entityParts = entity.GetType().ToString().Split('.');
                string entityName = entityParts[entityParts.Length - 1];
                PropertyInfo pf = GetType().GetProperty((entityName));
                if (pf != null)
                {
                    pf.SetValue(this, new EntityCollection(entity), null);
                }
                entityName = entityName + "_";
                pf = GetType().GetProperty((entityName));
                if (pf != null)
                {
                    pf.SetValue(this, entity, null);
                }
            }
            SetFlat(Flat);
        }

        ///Constructor for Joins with flat hierarchy
        public Proj_dept_budget(params Entity[] entities)
            : this(true, entities)
        {
        }

        ///<summary>
        /// Property for column Fiscal_year.
        ///</summary>
        [IsNotNullable]
        [IsPK]
        public Int32 Fiscal_year
        {
            get
            {
                return _FISCAL_YEAR;
            }
            set
            {
                _FISCAL_YEAR = value;
            }
        }
        ///<summary>
        /// Property for column Proj_id.
        ///</summary>
        [IsNotNullable]
        [IsPK]
        [MaxLength(5)]
        public String Proj_id
        {
            get
            {
                return _PROJ_ID;
            }
            set
            {
                _PROJ_ID = value;
            }
        }
        ///<summary>
        /// Property for column Dept_no.
        ///</summary>
        [IsNotNullable]
        [IsPK]
        [MaxLength(3)]
        public String Dept_no
        {
            get
            {
                return _DEPT_NO;
            }
            set
            {
                _DEPT_NO = value;
            }
        }
        ///<summary>
        /// Property for column Quart_head_cnt.
        ///</summary>
        public Int32 Quart_head_cnt
        {
            get
            {
                return _QUART_HEAD_CNT;
            }
            set
            {
                _QUART_HEAD_CNT = value;
            }
        }
        ///<summary>
        /// Property for column Projected_budget.
        ///</summary>
        public Decimal Projected_budget
        {
            get
            {
                return _PROJECTED_BUDGET;
            }
            set
            {
                _PROJECTED_BUDGET = value;
            }
        }
        #region DepartmentTable
        private EntityCollection _Department;
        ///<summary>
        /// Related table DepartmentTable as a collection for hierarchical retrieval.
        ///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(DepartmentTable), "Department")]
        public EntityCollection Department
        {
            get
            {
                return _Department;
            }

            set
            {
                _Department = value;
            }
        }
        private DepartmentTable _DepartmentTable;
        ///<summary>
        /// Related table DepartmentTable as a single object for flat retrieval.
        ///</summary>
        [NotInTable]
        public DepartmentTable DepartmentTable
        {
            get
            {
                return _DepartmentTable;
            }

            set
            {
                _DepartmentTable = value;
            }
        }
        #endregion
        #region Project
        private EntityCollection _Project;
        ///<summary>
        /// Related table Project as a collection for hierarchical retrieval.
        ///</summary>
        [NotInTable]
        [TypeContainedAttribute(typeof(Project), "Project")]
        public EntityCollection Project
        {
            get
            {
                return _Project;
            }

            set
            {
                _Project = value;
            }
        }
        private Project _Project_;
        ///<summary>
        /// Related table Project as a single object for flat retrieval.
        ///</summary>
        [NotInTable]
        public Project Project_
        {
            get
            {
                return _Project_;
            }

            set
            {
                _Project_ = value;
            }
        }
        #endregion
        /// <summary>
        /// Gets join for current entity and table.
        /// </summary>
        /// <param name="tableName">Table to join with entity.</param>
        /// <returns>Join definition for entity and table.</returns>
        public override DBJoin GetJoin(string tableName)
        {
            if (string.Compare(tableName, "Department", true) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
                left.Add(tableName + ".Dept_no");
                right.Add(GetType().Name + ".Dept_no");
                return new DBJoin(left, right, JoinTypeEnumeration.INNER);
            }
            if (string.Compare(tableName, "Project", true) == 0)
            {
                ArrayList left = new ArrayList();
                ArrayList right = new ArrayList();
                left.Add(tableName + ".Proj_id");
                right.Add(GetType().Name + ".Proj_id");
                return new DBJoin(left, right, JoinTypeEnumeration.INNER);
            }
            return null;
        }
    }
}


